from toee import *
from utilities import *

def san_dialog( attachee, triggerer ):
	if (game.global_vars[993] == 1):
		triggerer.begin_dialog( attachee, 1 )
	else:
		return RUN_DEFAULT
	return SKIP_DEFAULT

def switch_to_tarah( attachee, triggerer, line):
	npc = find_npc_near(attachee,8805)
	if (npc != OBJ_HANDLE_NULL):
		triggerer.begin_dialog(npc, line)
	return SKIP_DEFAULT

def run_off( attachee, triggerer ):
	for pc in game.party:
		attachee.ai_shitlist_remove( pc )
	attachee.runoff(attachee.location-3)
	persis = find_npc_near(attachee,8811)
	persis.runoff(attachee.location-3)
	villageboy = find_npc_near(attachee,14778)
	villageboy.runoff(attachee.location-3)
	return RUN_DEFAULT

def san_first_heartbeat( attachee, triggerer ):
	if (attachee.map == 5146 and game.global_vars[993] == 1):
		attachee.object_flag_unset(OF_OFF)
	return RUN_DEFAULT

def san_heartbeat( attachee, triggerer ):
	if (not game.combat_is_active()):
		if ( game.global_vars[993] == 1 ):
			if (is_better_to_talk(attachee, game.party[0])):
				attachee.turn_towards(game.party[0])
				game.party[0].turn_towards(attachee)
				game.party[0].begin_dialog( attachee, 1 )
	return RUN_DEFAULT

def is_better_to_talk(speaker,listener):
	if (speaker.can_see(listener)):
		if (speaker.distance_to(listener) <= 30):
			return 1
	return 0